<template>
  <div>
    <page-list :x-uri="uri" :doactions="doactions" :custom-components="customComponents" :checkbox-item="false">
      <!-- 自定义tab -->
      <template v-slot:page-tabs>
        <tabs :tabs="tabs" />
      </template>
      <!-- 页面操作按钮 -->
      <template v-slot:page-button>
        <el-button v-auth="'exam.module.config'" size="mini" type="primary" @click="create">新建套卷</el-button>
      </template>
    </page-list>
  </div>
</template>
<script>
import PageList from '@public/template/page_list.vue';
import Tabs from '../tabs';
import RollupStatus from './components/rollup_status.vue';
import RollupPrice from './components/rollup_price.vue';
import Redeem from './components/rollup_credit_redeem.vue';
export default {
  components: {
    PageList,
    Tabs
  },
  inject: ['reload'],
  data() {
    return {
      uri: '/exam/admin/module/' + this.$route.params.id + '/rollup/config',
      tabs: [
        {
          title: '套卷配置',
          uri: '/exam/module/' + this.$route.params.id + '/rollup/config',
          meta: {
            permission: 'exam.module.config'
          }
        }
      ],
      customComponents: {
        status: RollupStatus,
        credit_redeem: Redeem,
        price: RollupPrice
      },
      doactions: [
        { title: '试卷管理', meta: { permission: 'exam.module.config' }, callback: this.config },
        { title: '编辑', meta: { permission: 'exam.module.config' }, callback: this.edit },
        { title: '删除', meta: { permission: 'exam.module.config' }, callback: this.delete }
      ]
    };
  },
  methods: {
    // 新建
    create: function() {
      this.$router.push({ path: '/exam/module/' + this.$route.params.id + '/rollup/create' });
    },
    // 编辑
    edit: function({ row }) {
      this.$router.push({ path: '/exam/module/' + this.$route.params.id + '/rollup/' + row.id + '/edit' });
    },
    config: function({ row }) {
      this.$router.push({ path: '/exam/module/' + this.$route.params.id + '/rollup/' + row.id + '/paper' });
    },
    // 删除
    delete: function({ row }) {
      this.$box
        .confirm('确认删除吗')
        .then(() => {
          this.$http.delete(
            '/exam/admin/module/' + this.$route.params.id + '/rollup/' + row.id + '/delete',
            {},
            response => {
              this.$message.success(response.msg, _ => {
                this.reload();
              });
            },
            error => {
              this.$message.error(error.msg);
            }
          );
        })
        .catch(() => {});
    }
  }
};
</script>
